home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _m_ / minesweeper / mine.cc < prev    next >
C/C++ Source or Header  |  1994-12-23  |  3KB  |  123 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. ///////////////////////////////////////////////////////////////////////////
  3. //
  4. //  AMIGA Minesweeper - the driver-routine
  5. //
  6. //  (c) 1992 Hubert Feyrer (c9020@rrzc1.rz.uni-regensburg.de)
  7. //
  8. ///////////////////////////////////////////////////////////////////////////
  9.  
  10. /*
  11. ** Diverse "C"-Header
  12. */
  13. #define class _class
  14. #define template _template
  15. #define IntuitionBase IntuiBase
  16. #define GfxBase GraphBase
  17. extern "C" {
  18. # include <stdio.h>
  19. # include <stdlib.h>
  20. # include <exec/types.h>
  21. # include <exec/exec.h>
  22. # include <exec/Ports.h>
  23. # include <devices/timer.h>
  24. # include <utility/tagitem.h>
  25. # include <intuition/intuition.h>
  26. # include <intuition/intuitionbase.h>
  27. # include <intuition/gadgetclass.h>
  28. # include <graphics/gfxbase.h>
  29. # include <clib/gadtools_protos.h>
  30. # include <clib/intuition_protos.h>
  31. # include <clib/exec_protos.h>
  32. # include <math.h>
  33. }    
  34. #undef IntuitionBase
  35. #undef GfxBase 
  36. #undef class
  37. #undef template
  38.  
  39. /*
  40. ** C++-Header
  41. */
  42. #include "mine.h"
  43. #include "field.h"
  44.  
  45. Field ***minefield;                    // minefield[x][y]->check();
  46. int lenx=8;                            // Minenfeld-Größe x (max: 57)
  47. int leny=8;                            // Minenfeld-Größe y (max: 36)
  48. int playtime;                          // Verspielte Zeit in Sekunden
  49.  
  50.  
  51. //*
  52. //* Spiel gewonnen!
  53. //*
  54. void game_won(void)
  55. {
  56.     SetWindowTitles(win,"You WIN!",-1);
  57. }
  58.  
  59.  
  60. //*
  61. //* Spiel verloren!
  62. //*
  63. void game_lost(void)
  64. {
  65.     showmines();
  66.     SetWindowTitles(win,"You blew it!",-1);
  67. }
  68.  
  69.  
  70. //*
  71. //* Hauptprogramm
  72. //*
  73. int main(int argc, char *argv[])
  74. {
  75.     argv0=argv[0];
  76.     int pr=15;
  77.  
  78.     if(argc>2){
  79.     if((lenx=atoi(argv[1]))<2) lenx=8;             // Anzahl x-Felder
  80.     if((leny=atoi(argv[2]))<2) leny=8;             // Anzahl y-Felder
  81.     if(argc>3){
  82.         if((pr=atoi(argv[3]))<0 || pr>99) pr=15;   // Wieviel Prozent vermint
  83.     }
  84.     }
  85.  
  86.     init(pr);
  87.     hidemines(pr);
  88.  
  89.     int idle=0;                    // Schleife in play() wartet auf Closewindow
  90.     while(1){
  91.     GameStat r=play(idle);
  92.  
  93.     if(r==GAME_QUIT)
  94.       shutdown(0);
  95.       
  96.     switch(r){
  97.       case GAME_WON:
  98.         game_won();
  99.         idle=1;
  100.         break;
  101.       case GAME_LOST:
  102.         game_lost();
  103.         idle=1;
  104.         break;
  105.       case GAME_RESTART:
  106.         removemines();
  107.         hidemines(pr);
  108.         playtime=0;
  109.         sprintf(ttimegad,"%04d",playtime);
  110.         GT_SetGadgetAttrs(timegad,win,NULL,
  111.                   GTTX_Text,ttimegad,
  112.                   TAG_END);
  113.         RefreshGList(timegad,win,NULL,1);
  114.         countdown=lenx*leny;
  115.         idle=0;
  116.         break;
  117.       default:
  118.         shutdown(20,"Unknown returncode from play()");
  119.     }
  120.     }
  121.     /*NOTREACHED*/
  122. }
  123.